package com.zhuojy.equity.mall.admin.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuojy.equity.mall.admin.common.entity.Notice;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.service.NoticeService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("notice")
@RequiredArgsConstructor
@Api("公告管理")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    //查询
    @RequestMapping("queryNotice")
    public ResultEntity queryNotice(@RequestBody Notice notice) {
        try {
            IPage page = noticeService.queryNotice(notice);
            return ResultEntity.OK(page);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("操作错误");
        }
    }
    //删除
    @RequestMapping("deleteNotice")
    public ResultEntity deleteNotice(@RequestParam(value = "id") Integer id) {
        try {
            noticeService.deleteNotice(id);
            return ResultEntity.OK("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("操作错误");
        }
    }
    /**
     * 新增/修改
     */
    @RequestMapping("addNotice")
    public ResultEntity addNotice(@RequestBody Notice notice) {
        try {
            noticeService.addNotice(notice);
            return ResultEntity.OK("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.ERROR("操作错误");
        }
    }
}

